package com.bwhx.eruler.controller;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.bwhx.eruler.bean.Page;
import com.bwhx.eruler.bean.ShirtSizeRule;
import com.bwhx.eruler.bean.Staff;
import com.bwhx.eruler.bean.casdilly.CasdillyCustomer;
import com.bwhx.eruler.service.ShirtSizeRuleService;
import com.bwhx.eruler.util.Constant;

@Controller
@RequestMapping("/shirt_sizerule")
public class ShirtSizeRuleController extends BaseController {
	
	@Autowired
	ShirtSizeRuleService shirtSizeRuleService;
	
 
	
	
	@ResponseBody
	@RequestMapping("/list.ashx")
	public HashMap<String,Object> listAll(HttpServletRequest request){
		HashMap<String,Object> resultMap = new HashMap<String,Object>();
		
		try {
			List<ShirtSizeRule> shirtSizeRuleList = shirtSizeRuleService.listAll();
			resultMap.put(Constant.DATA, shirtSizeRuleList);
			resultMap.put("data_standardshirt", shirtSizeRuleService.listAllStandardShirt());
			resultMap.put(Constant.STATUS, Constant.STATUS_SUCCESS);
			resultMap.put(Constant.MSG, Constant.MSG_SUCCESS);
		} catch (Exception e) {
			log.error(getTrace(e));
			resultMap.put(Constant.STATUS, Constant.STATUS_FAIL);
			resultMap.put(Constant.MSG, Constant.MSG_FAIL);
		}
		
		
		return resultMap;
		
	}

	
	
	/*@ResponseBody
	@RequestMapping(value = "/page.list.ashx")
	 public Map<String,Object> sizeRulerList(Integer page,Integer rows,ShirtSizeRule sizeRulerHK) {
		

		
		//每页的开始记录
        int start = (page-1)*rows;
        Page p = new Page(start,rows,sizeRulerHK);
		Map<String,Object> resultMap = new HashMap<String,Object>();
		try{
			List<ShirtSizeRule> list = shirtSizeRuleService.list(p);
			Integer count = shirtSizeRuleService.count(sizeRulerHK);

					
			resultMap.put("total",count );//total键 存放总记录数，必须的  
			resultMap.put("rows",list);//rows键 存放每页记录 list 
			
		
			
		}catch(Exception e){
			log.error(getTrace(e));
			resultMap.put("msg", "失败！");
			resultMap.put("status", "0");
		}
		
	    return resultMap;  
	  }
	
	@ResponseBody
	@RequestMapping(value = "/page.del.ashx")
	public String del(ShirtSizeRule shirtSizeRule) {
		try{
			
			Staff sessionUser = this.getSessionStaff();	
			shirtSizeRule.setModifierID (sessionUser.getsId().toString());
			shirtSizeRule.setModifyTime(new Date());
			shirtSizeRuleService.delete(shirtSizeRule);
			
		}catch(Exception e){
			log.error(getTrace(e));
			return "fail";
		}
		
		
	    return "success";  
	  }
	
	
	
	@ResponseBody
	@RequestMapping(value = "/page.saveOrUpdate.ashx")
	public String saveOrUpdate(ShirtSizeRule shirtSizeRule) {
		try{
			
			Staff sessionUser = this.getSessionStaff();
			
			
			if(shirtSizeRule.getsRHKID().equals("-1")){
				shirtSizeRule.setCreatorID(sessionUser.getsId().toString());
				shirtSizeRule.setCreateTime(new Date());
				ShirtSizeRule sr = shirtSizeRuleService.findConflict(shirtSizeRule);
				
				if(sr==null){
					shirtSizeRuleService.insert(shirtSizeRule);
				}else{
					return "conflict";  
				}
			
				
				
			}else{
				
				shirtSizeRule.setModifierID (sessionUser.getsId().toString());
				shirtSizeRule.setModifyTime(new Date());
				
				ShirtSizeRule sr = shirtSizeRuleService.findConflict(shirtSizeRule);
				
				if(sr==null){
					shirtSizeRuleService.update(shirtSizeRule);
				}else{
					return "conflict";  
				}
				
				

			}
			
		}catch(Exception e){
			log.error(getTrace(e));
			return "fail";
		}
		
		
	    return "success";  
	  }*/
	
	
	
	

}
